<?php

namespace App\Admin\Controllers;

use DB;
use Validator;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;

class HomeController extends Controller
{
	/**
	 * [index description]
	 * @return [type] [description]
	 */
	public function index()
	{
		return view('admin.home.index');
	}

	/**
	 * [lockScreen description]
	 * @return [type] [description]
	 */
	public function lockScreen()
	{
		$user = \Auth::guard('admin')->user();
		return view('admin.home.lock', compact('user'));
	}

	/**
	 * [unlock description]
	 * @return [type] [description]
	 */
	public function unlock(Request $request)
	{
    	$validator = Validator::make($request->all(), [
			'password' => 'required'
        ], [
        	'password.required' => '请输入密码'
        	]);
		$user = request(['name', 'password']);
		if (!\Auth::guard('admin')->attempt($user)) {
	        $validator->after(function($validator){
	            $validator->errors()->add('password','密码错误');
	        });			
		}
        if ($validator->passes()) {
        	return redirect('/admin/home');
        } else {
        	return Redirect::back()->withInput()->withErrors($validator->errors());
        }
	}
}